
public class TestMain {
    public static void main(String[] args) {

        Solution solution = new Solution();

//        head = [1,2,6,3,4,5,6], val = 6
        ListNode l = new ListNode();
        addHeadNode(l,1);
        addTailNode(l,2);
        addTailNode(l,6);
        addTailNode(l,4);
        addTailNode(l,5);
        addTailNode(l, 6);

        printListNode(l);

        solution.removeElements(l,6);

        printListNode(l);


    }

    private static void addHeadNode(ListNode l, int val) {
        ListNode newNode = new ListNode();
        newNode.next = l.next;
        newNode.val = val;
        l.next = newNode;
    }

    public static void addTailNode(ListNode head, int val) {
        ListNode cur;
        cur = head.next;
        ListNode newNode = new ListNode();
        newNode.next = null;
        newNode.val = val;
        if(cur != null){
            while (cur.next != null) cur = cur.next;
            cur.next = newNode;
        }else head.next = newNode;
    }

    public static void printListNode(ListNode linkedList){
        ListNode head = linkedList;
        while (head.next != null){
            System.out.print(head.next.val + " ");
            head = head.next;
        }
        System.out.println();
    }




}
